﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Slam;
using Microsoft.SharePoint;
using Slam.Configuration;
using Slam.Data;
using Slam.Logging;
using Slam.SharePoint;
using Slam.Events;
using System.Xml.Linq;
using System.Collections;
using SlamCms.SharePoint.Tagging.FieldTypes;
using SlamCms.SharePoint.SlamProfiles.ContentItem.Data;
using SlamCms.SharePoint.SlamProfiles.ContentItem.Services;
using SlamCms.SharePoint.Tagging.Services;
using System.Text.RegularExpressions;

namespace SlamCms.SharePoint.SlamProfiles.ContentItem
{
	public class ContentItemContentTypeItemCreator : ContentTypeItemCreator
	{
		private IConfigurationManager _configuration;
		private DataService _dataService;
		private IDataServices _dataServices;
		private string _dataSchema;
		private ILogger _logger;

		#region Constructors

		public ContentItemContentTypeItemCreator(IDataServices dataServices, IConfigurationManager configuration, ILogger logger)
			: base(dataServices, configuration, logger)
		{
			_configuration = configuration;
			_dataServices = dataServices;
			_dataSchema = ((XmlSqlDataMapping)configuration.DataMapping).GetDataSchema();
			_dataService = new DataService(configuration.GetSection<ConnectionStringSection>("ConnectionStrings").Default);
			_logger = logger;

			_configuration.RegisterSection("ContentItem",
				config =>
				{
					object section = null;
					if (config is XDocument)
					{
						section = new ContentItemProfileSection((XDocument)config);
					}
					return section;
				});
		}

		#endregion

		public override bool Create(SPListItem listItem)
		{
			return ContentItemEvents.Create(listItem, _dataServices, _configuration, _logger, _dataService, _dataSchema, "Create CT");
		}
	}
}
